package org.ejc.api.accomodation;

import java.util.ArrayList;
import java.util.Collection;

import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.naming.NamingException;

import org.ejc.exception.EJCPersistenceException;
import org.ejc.persist.model.AccomodationType;
import org.ejc.util.EJCUtils;
import org.hibernate.Session;

/**
 * @author zac
 * 
 * @ejb.bean type="Stateless" name="AccomodationAPI"
 *           description="AccomodationAPI session bean"
 *           local-jndi-name="org.ejc/AccomodationAPILocalHome"
 *           jndi-name="org.ejc/AccomodationAPIHome" view-type="both"
 * 
 * @ejb.ejb-ref ejb-name="AccomodationAPI" ref-name="ejb/AccomodationAPI"
 *              view-type="both"
 * 
 * @ejb.transaction type="RequiresNew"
 * @ejb.util generate = "physical"
 */
public abstract class AccomodationAPIBean implements SessionBean{

	/**
	 * Return a List of Accomodation Types.
	 * 
	 * @ejb.interface-method view-type="both"
	 * 
	 */
	public Collection getAccomodationTypes() throws NamingException, EJBException {
		Session hsession = null;
		try {
			hsession = EJCUtils.getHibernateSession();
			return hsession.createCriteria(AccomodationType.class).list();
		} catch (EJCPersistenceException epe) {
			epe.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (hsession != null) {
				hsession.close();
			}
		}
		return new ArrayList();
	}

}